package com.carepad.dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import com.carepad.entity.mapper.ChartData;

public interface ChartDataMapper {
	/*@Select("SELECT bphtemp.BPH AS BPH, bpltemp.BPL AS BPL, prtemp.PR AS PR, bttemp.BT AS BT, DATE_FORMAT(bphtemp.DATEREG, '%Y-%m-%d') AS DATEREG "+
			"FROM "+
			"(SELECT "+
			"CASE WHEN ACTION_ITEM = '血圧（上）' THEN ANSWER END AS BPH, EXECUTION_DATE AS DATEREG "+
		  	"FROM tbl_records where HCS_ID = #{hcsid} AND ACTION_ITEM = '血圧（上）' AND (EXECUTION_DATE BETWEEN #{startDate} AND #{lastDate})) AS bphtemp LEFT OUTER JOIN "+
		
			"(SELECT "+
			"CASE WHEN ACTION_ITEM = '血圧（下）' THEN ANSWER END AS BPL, EXECUTION_DATE AS DATEREG "+
			"FROM tbl_records where HCS_ID = #{hcsid} AND ACTION_ITEM = '血圧（下）' AND (EXECUTION_DATE BETWEEN #{startDate} AND #{lastDate})) AS bpltemp ON bpltemp.DATEREG = bphtemp.DATEREG LEFT OUTER JOIN "+
		
			"(SELECT "+
			"CASE WHEN ACTION_ITEM = '脈拍' THEN ANSWER END AS PR, EXECUTION_DATE AS DATEREG "+
			"FROM tbl_records where HCS_ID = #{hcsid} AND ACTION_ITEM = '脈拍' AND (EXECUTION_DATE BETWEEN #{startDate} AND #{lastDate})) AS prtemp ON prtemp.DATEREG = bphtemp.DATEREG LEFT OUTER JOIN "+
		
			"(SELECT "+
			"CASE WHEN ACTION_ITEM = '体温' THEN ANSWER END AS BT, EXECUTION_DATE AS DATEREG "+
			"FROM tbl_records where HCS_ID = #{hcsid} AND ACTION_ITEM = '体温' AND (EXECUTION_DATE BETWEEN #{startDate} AND #{lastDate})) AS bttemp  ON bttemp.DATEREG = bphtemp.DATEREG ORDER BY bphtemp.DATEREG")
	*/
	@Select("SELECT SBP AS BPH, DBP AS BPL, PR, BT,  DATE_FORMAT(EXECUTION_DATE, '%Y-%m-%d') AS DATEREG, ACTION_TIME_FROM AS ACTIONTIME " +
			"FROM tbl_vital " + 
			"WHERE HCS_ID = #{hcsid} AND (EXECUTION_DATE BETWEEN #{startDate} AND #{lastDate} ) ORDER BY EXECUTION_DATE, ACTION_TIME_FROM" )
	@ResultMap(value = "ChartDataMap")
	List<ChartData> findChartDataListByHcsId(
			@Param("hcsid") String hcsid, 
			@Param("startDate") String startDate, 
			@Param("lastDate") String lastDate);
}
